.TH std::basic_ostream::put 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_ostream::put \- std::basic_ostream::put

.SH Synopsis
   basic_ostream& put( char_type ch );

   Behaves as an UnformattedOutputFunction. After constructing and checking the sentry
   object, writes the character ch to the output stream.

   If the output fails for any reason, sets badbit.

.SH Parameters

   ch - character to write

.SH Return value

   *this

.SH Notes

   This function is not overloaded for the types signed char or unsigned char, unlike
   the formatted operator<<.

   Unlike formatted output functions, this function does not set the failbit if the
   output fails.

.SH Example


// Run this code

 #include <fstream>
 #include <iostream>

 int main()
 {
     std::cout.put('a'); // normal usage
     std::cout.put('\\n');

     std::ofstream s("/does/not/exist/");
     s.clear(); // pretend the stream is good
     std::cout << "Unformatted output: ";
     s.put('c'); // this will set badbit, but not failbit
     std::cout << " fail=" << bool(s.rdstate() & s.failbit);
     std::cout << " bad=" << s.bad() << '\\n';
     s.clear();
     std::cout << "Formatted output:   ";
     s << 'c'; // this will set badbit and failbit
     std::cout << " fail=" << bool(s.rdstate() & s.failbit);
     std::cout << " bad=" << s.bad() << '\\n';
 }

.SH Output:

 a
 Unformatted output:  fail=0 bad=1
 Formatted output:    fail=1 bad=1

.SH See also

   operator<<(std::basic_ostream) inserts character data or insert into rvalue stream
                                  \fI(function template)\fP
   write                          inserts blocks of characters
                                  \fI(public member function)\fP
